<template>
    <div class="release">
       <p>发布资讯</p>
        <Form :model="formItem" label-position="right" :label-width="80" style="margin-top: 20px" enctype="multipart/form-data">
            <FormItem label="资讯标题：">
                <Input v-model="formItem.title" type="text"  placeholder="内容详情..." />
            </FormItem>
            <FormItem label="正文：">
                <div id="editorElem"></div>
                <!--<Input v-model="formItem.content" type="textarea" :rows="4" placeholder="内容详情..." />-->
            </FormItem>
        </Form>
        <div style="padding-left: 100px">
            <Button type="primary" size="large" style="width: 206px" @click="subimt">发布</Button>
        </div>
    </div>
</template>

<script>
    import E from 'wangeditor'
    export default {
        name: "Release",
        data () {
            return {
                formItem:{},
                id:'',
                editorContent:'',
            }
        },
        methods: {
            subimt () {
                let _this =this
                _this.$post('/api/activity/addConsultation',
                    {
                        token:_this.$token,
                        title:_this.formItem.title,
                        content:_this.editorContent,
                        consultation_id:_this.id
                    }, function (res) {
                        _this.$message.success(res.msg);
                        _this.$router.push({path:'/my/myinfo/list'})
                    }, function (errcode, errmsg,err) {
                        console.log(err)
                        console.log(errmsg)
                    })
            }
        },
        mounted() {
            var editor = new E('#editorElem')
            editor.customConfig.onchange = (html) => {
                this.editorContent = html
            }
            editor.customConfig.uploadImgServer = this.$IUrl  // 上传图片到服务器
            editor.customConfig.uploadFileName = 'file';
            editor.customConfig.uploadImgHooks = {
                customInsert: function (insertImg, result, editor) {
                    var url = result.data[0]
                    insertImg(url)
                }
            }
            editor.create()
        }

    }
</script>

<style scoped lang="less">
    @import "../../../style/style";
    .release{
        border: 1px solid @border-color;
        padding: 15px !important;
      p{
          color: @theme-color-dark;
          font-size: 18px;
          padding-bottom: 10px;
          border-bottom: 1px solid @theme-color-dark;
      }

    }
</style>